package org.giovanolli.mumi.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * The Class City.
 */
@Entity
@Table(name = "city")
public class City extends IdentificableEntity {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 2699269844915304387L;

	/** The name. */
	@Column(name = "name")
	private String name;

	/** The region. */
	@ManyToOne
	@JoinColumn(name = "region_id")
	private Region region;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.giovanolli.mumi.entities.IdentificableEntity#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		City other = (City) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (region == null) {
			if (other.region != null)
				return false;
		} else if (!region.equals(other.region))
			return false;
		return true;
	}

	/**
	 * Gets the name.
	 * 
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Gets the region.
	 * 
	 * @return the region
	 */
	public Region getRegion() {
		return region;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.giovanolli.mumi.entities.IdentificableEntity#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((region == null) ? 0 : region.hashCode());
		return result;
	}

	/**
	 * Sets the name.
	 * 
	 * @param name
	 *            the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Sets the region.
	 * 
	 * @param region
	 *            the new region
	 */
	public void setRegion(Region region) {
		this.region = region;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.osoftware.mumi.dao.model.BaseObject#toString()
	 */
	@Override
	public String toString() {
		return "City [name=" + name + ", region=" + (region != null ? region.getName() : "NONE") + ", toString()=" + super.toString() + "]";
	}

}
